#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 1e5 + 5;

int n, m;
int a[N], b[N], num;
struct Node {
  int cnt;
  int ch[2];
} tr[N << 5];
#define cnt(p) tr[p].cnt
#define lc(p) tr[p].ch[0]
#define rc(p) tr[p].ch[1]
int root[N];
int head[N];
int ver[N << 1], Next[N << 1], tot;
void add(int u, int v) {
  ++tot;
  ver[tot] = v;
  Next[tot] = head[u];
  head[u] = tot;
}
int dep[N], st[N][18];
void dfs(int u, int fu) {
  st[u][0] = fu;
  dep[u] = dep[fu] + 1;
  for (int i = head[u]; i; i = Next[i]) {
    int v = ver[i];
    if (v == fu) continue;
    dfs(v, u);
  }
}
void init_st() {
  rep(j, 1, 16) rep(i, 1, n) st[i][j] = st[st[i][j - 1]][j - 1];
}
int lca(int u, int v) {
  if (dep[u] < dep[v]) swap(u, v);
  int d = dep[u] - dep[v];
  per(j, 16, 0) if (d & (1 << j)) u = st[u][j];
  if (u == v) return u;
  per(j, 16, 0) if (st[u][j] != st[v][j]) u = st[u][j], v = st[v][j];
  return st[u][0];
}
int newnode(int p) {
  static int id = 0;
  ++id;
  cnt(id) = cnt(p);
  lc(id) = lc(p);
  rc(id) = rc(p);
  return id;
}
void update(int x, int &p, int l, int r) {
  p = newnode(p);
  cnt(p)++;
  if (l == r) return;
  int mid = (l + r) >> 1;
  if (x <= mid)
    update(x, lc(p), l, mid);
  else
    update(x, rc(p), mid + 1, r);
}
int query(int k, int p1, int p2, int p3, int p4, int l, int r) {
  if (l == r) return l;
  int mid = (l + r) >> 1;
  int x = cnt(lc(p1)) + cnt(lc(p2)) - cnt(lc(p3)) - cnt(lc(p4));
  if (k <= x)
    return query(k, lc(p1), lc(p2), lc(p3), lc(p4), l, mid);
  else
    return query(k - x, rc(p1), rc(p2), rc(p3), rc(p4), mid + 1, r);
}
void dfs2(int u, int fu) {
  root[u] = root[fu];
  update(a[u], root[u], 1, num);
  for (int i = head[u]; i; i = Next[i]) {
    int v = ver[i];
    if (v == fu) continue;
    dfs2(v, u);
  }
}
void build() {
  rep(i, 1, n) b[i] = a[i];
  sort(b + 1, b + n + 1);
  num = unique(b + 1, b + n + 1) - b - 1;
  rep(i, 1, n) a[i] = lower_bound(b + 1, b + num + 1, a[i]) - b;
  dfs2(1, 0);
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> m;
  rep(i, 1, n) cin >> a[i];
  rep(i, 2, n) {
    int u, v;
    cin >> u >> v;
    add(u, v), add(v, u);
  }
  dfs(1, 0);
  init_st();
  build();

  int ans = 0;
  while (m--) {
    int u, v, k;
    cin >> u >> v >> k;
    u ^= ans;
    int x = lca(u, v);
    int y = st[x][0];
    int z = query(k, root[u], root[v], root[x], root[y], 1, num);
    ans = b[z];
    cout << ans << endl;
  }
  return 0;
}